<!DOCTYPE html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <title>数据统计</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/public/layermobile/css/layer.css">
    <link rel="stylesheet" href="/assets/doorctrl/css/style.css"/>
    <link rel="stylesheet" href="/assets/doorctrl/css/fonts.css"/>
</head>
<body>
<div class="wraper">
    <form action="/Doorctrl/DoorctrlStat/yesterdayNoBackDetail/doorctrlId/{BEESCRM:$doorctrlId}" method="post">
        <div class="header font-16 flex padding">
            <a href="/Doorctrl/DoorctrlStat/index/doorctrlId/{BEESCRM:$doorctrlId}" style="color:#fff;"><div class="iconfont icon-zuo font-24"></div></a>
            <div class="seek-name">
                <input type="text" placeholder="请输入完整的学生姓名进行搜索" id="real_name" name="real_name" value="{BEESCRM:$_REQUEST['real_name']}" style="color:#2a2a2a;"/>
            </div>
            <!--<button type="submit" style="display: none;" id="js_search_btn">搜索</button>-->
            <span id="search" style="cursor: pointer;">搜索</span>
        </div>
    </form>
    <div class="tab margin-10" style="margin-bottom: 10px;">
        <a href="/Doorctrl/DoorctrlStat/importantDetail/doorctrlId/{BEESCRM:$doorctrlId}" class="tab-cell ">重点</a>
        <a href="/Doorctrl/DoorctrlStat/yesterdayNoBackDetail/doorctrlId/{BEESCRM:$doorctrlId}" class="tab-cell  bgc-blue">夜不归宿</a>
        <a href="/Doorctrl/DoorctrlStat/yesterdayLateDetail/doorctrlId/{BEESCRM:$doorctrlId}" class="tab-cell">晚归</a>

    </div>
    <if condition="!empty($noBackList)">
        <div class="scroll-box">
            <volist name="noBackList" id="vo">
                <div class="box Student title margin-10">
                    <a href="javascript:;" class="flex font-color">
                        <div>
                            <p>{BEESCRM:$vo['user_info']['real_name']}</p>
                            <p class="margin-8 font-gray font-12"><span>{BEESCRM:$vo['dept_name']}</span> <span class="margin-l18">{BEESCRM:$vo['user_info']['mobile']}</span>
                            </p>
                        </div>
                        <div class="iconfont icon-zhankai"></div>
                    </a>
                    <div class="prove font-12 hide">
                        <volist name="vo['enter_log']" id="logs">
                            <p class="flex">
                                <span>{BEESCRM:$logs['enter_time']|date='m-d H:i:s', ###}</span>
                            <span >
                                <if condition="$logs['from'] eq 0">由系统确认<if condition="$logs['status'] eq 0">正常</if><if condition="$logs['status'] eq 1">晚归</if><if condition="$logs['status'] eq 2">{BEESCRM:$nobackLable}</if></if>
                                <if condition="$logs['from'] neq 0 and $logs['controller_id']">由{BEESCRM:$logs['controller_name']}确认<if condition="$logs['status'] eq 0">正常</if><if condition="$logs['status'] eq 1">晚归</if><if condition="$logs['status'] eq 2">未归</if></if>
                            </span>
                            </p>
                        </volist>
                        <if condition="empty($vo['enter_log'])">
                            <p class="flex">
                                <span>{BEESCRM:$vo['last_out_time']|date='m-d H:i:s', ###}</span>
                                <span >由系统确认夜不归宿</span>
                            </p>
                        </if>

                        <!--刷卡记录-->
                        <if condition="!empty($vo['event_record'])">
                            <div style="border-top: 1px solid #e6e6e6; margin: 10px 0;"></div>
                            <p class="flex">
                                <span>{BEESCRM:$vo['event_record'][0]['event_time']|date='m-d H:i:s', ###}<!--（<if condition="$record['in_out'] == 1">进</if><if condition="$record['in_out'] == 2">出</if>）--></span>
                                <span >{BEESCRM:$vo['event_record'][0]['door_name']}<if condition="$vo['event_record'][0]['in_out'] eq 1">(进)</if><if condition="$vo['event_record'][0]['in_out'] eq 2">(出)</if></span>
                            </p>
                        </if>
                    </div>
                </div>
            </volist>
        </div>
    </if>
    <div style="padding: 20px;text-align: center" class="hide js_no_more">
        <p class="font-12 font-gray">没有更多记录了</p>
    </div>
    <if condition="empty($noBackList)">
        <div class="NO-post">
            <div class="font-gray no-data"><p>暂无数据</p></div>
        </div>
    </if>

    <div class="pop-box hide">
        <div class="pop-chosename">
            <div class="pop-titles text-center">
                选择学生
            </div>
            <div class="pop-main font-gray">

                <div class="pop-information flex flex-start user_check" data-user_id="user_id">
                    <div class="pop-circle ">
                    </div>
                    <div>
                        <span class="user_name"></span> (<span class="user_class"></span>)
                    </div>
                </div>

            </div>
        </div>
    </div>

</div>
<input type="hidden" id="doorctrlId" name="doorctrlId" value="{BEESCRM:$doorctrlId}" />
<script src="/assets/public/jquery-2.1.0.min.js"></script>
<script src="/assets/doorctrl/js/public.js"></script>
<script src="/assets/public/layermobile/layer.js"></script>
<script src="/assets/doorctrl/js/doorctrlStat/yesterdayList.js"></script>
<script>
    $(document).ready(function () {
        var type = 2;
        var page = 2;
        var real_name = $("input[name='real_name']").val().trim();
        //页面初始化时候加载,不使用，已经用php渲染了
        //ajaxGetData();

        //滚动条加载
        $(window).scroll(function () {
            if ($(document).scrollTop()+$(window).height() >= $(document).height()) {
                ajaxGetData();
            }
        });

        //点击搜索按钮
        $(document).on('click','#search',function () {
            //$('#js_search_btn').trigger('click');
            var real_name = $('#real_name').val();
            if (real_name == '') {
                fm.alert('请输入完整的姓名进行搜索！');return false;
            }
            $.ajax({
                url:"/Doorctrl/DoorctrlStat/ajaxGetUserId/doorctrlId/{BEESCRM:$doorctrlId}",
                type:'post',
                async:false,
                data:{'real_name':real_name},
                dataType:'json',
                success:function(res){
                    if (res.status == 'S') {
                        if (res.user_id != 0) {
                            location.href = "/Doorctrl/DoorctrlStat/searchDetail/user_id/"+res.user_id+"/type/noback/doorctrlId/{BEESCRM:$doorctrlId}";
                        }
                        else if (res.user_info) {
                            setUser(res.user_info);
                            $('.pop-box').show();
                        }
                    }
                    else {
                        fm.alert(res.message);
                    }
                    return false;
                }

            });
            return false;
        });

        function setUser(userInfo) {
            $('.user_check').first().nextUntil('.user_check').remove();
            for (var i = 0; i < userInfo.length; i++) {
                $('.user_check').last().after($('.user_check').last().clone());
                $('.user_check').eq(i).data('user_id',userInfo[i].user_id);
                $('.user_check .user_name').eq(i).html(userInfo[i].real_name);
                $('.user_check .user_class').eq(i).html(userInfo[i].class_name);
            }
            $('.user_check').eq(userInfo.length).remove();
        }

        // 点击选择用户
        $(document).on('click','.user_check',function(){
            var user_id = $(this).data('user_id');
            $('.pop-box').hide();
            location.href = "/Doorctrl/DoorctrlStat/searchDetail/user_id/"+user_id+"/type/noback/doorctrlId/{BEESCRM:$doorctrlId}";
            return false;
        });

        $(".tab").on("click",".tab-cell",function(){
            $(this).addClass("bgc-blue").siblings().removeClass("bgc-blue");
        });
        $('.pop-information').click(function () {
            $(this).children('.pop-circle').addClass('pop-active');
            $(this).siblings().children('.pop-circle').removeClass('pop-active');
            $('.pop-box').addClass('hide');
        });
        $('.pop-box').click(function () {
            $(this).addClass('hide');
        });
        $('.pop-titles').click(function (e) {
            e.stopPropagation()
        });

        
        //ajax获取数据
        function ajaxGetData() {
            var _html = '';
            $.ajax({
                url : "/Doorctrl/DoorctrlStat/ajaxYesterdayDetail/doorctrlId/{BEESCRM:$doorctrlId}",
                type : "POST",
                data : {"type" : type,"page" : page, real_name : real_name},
                dataType : "JSON",
                beforeSend : function () {
                    $('.load').show();
                },
                success : function (res) {
                    $('.load').hide();
                    if(res.status == 'S'){
                        for(var i=0;i<res.data.length;i++){
                            //确认日志循环
                            var log_html = '';
                            var controller_name = '系统';
                            var type = '';
                            if(res.data[i].enter_log.length > 0){
                                for(var j=0;j<res.data[i].enter_log.length;j++){
                                    //判断是系统还是管理员
                                    if(res.data[i].enter_log[j].from > 0){
                                        controller_name = res.data[i].enter_log[j].contoller_name;
                                    }

                                    //判断状态
                                    if(res.data[i].enter_log[j].status == 1){
                                        type = '晚归';
                                    }else if(res.data[i].enter_log[j].status == 2){
                                        type = "{BEESCRM:$nobackLable}";
                                    }else{
                                        type = '正常';
                                    }
                                    log_html += '<p class="flex"><span>'+ res.data[i].enter_log[j].new_enter_time +'</span>' +
                                    '<span >由'+ controller_name +'确认'+type+'</span></p>';
                                }
                            }else{
                                log_html = '<span>'+ res.data[i].last_in_time +'</span>' +
                                '<span class="pull-right">由系统确认夜不归宿</span>';
                            }

                            var event_html = '';
                            if(res.data[i].event_record.length > 0){
                                var in_out = '';
                                if(res.data[i].event_record[0]['in_out'] == 1){
                                    in_out = '(进)';
                                }
                                if(res.data[i].event_record[0]['in_out'] == 2){
                                    in_out = '(出)';
                                }
                                event_html = '<div style="border-top: 1px solid #e6e6e6; margin: 10px 0;"></div>' +
                                '<p class="flex">' +
                                '<span>' + res.data[i].event_record[0]['new_event_time']+ '</span>' +
                                '<span >'+res.data[i].event_record[0]['door_name']+ in_out +'</span>' +
                                '</p>';
                            }


                            _html += '<div class="box Student title margin-10">' +
                                    '<a href="javascript:;" class="flex font-color">' +
                                    '<div>' +
                                    '<p>'+ res.data[i].user_info.real_name+ '</p>' +
                                    '<p class="margin-8 font-gray font-12"><span>' + res.data[i].dept_name + '</span> <span class="margin-l18">'+(res.data[i].user_info.mobile ? res.data[i].user_info.mobile :'') + '</span>' +
                                    '</p>' +
                                    '</div>' +
                                    '<div class="iconfont icon-zhankai"></div>' +
                                    '</a>' +
                                    '<div class="prove font-12 hide">' + log_html + event_html + '</div>' +
                                    '</div>'
                        }
                        if(_html != ''){
                            $(".js_no_more").addClass('hide');
//                            $(".scroll-box").html(_html);
                            $(".scroll-box").append(_html);
                        }else{
                            $(".js_no_more").removeClass('hide');
                        }
                        page += 1;
                    }else{
                        $.alert('error',res.message);
                    }
                },
                error : function () {
                    $.alert('error','网络错误，请重试');
                }
            });
        }
    });
</script>
</body>
</html>